import 'package:flutter/material.dart';

class ActionChipDemo extends StatefulWidget {
  const ActionChipDemo({Key? key}) : super(key: key);

  @override
  _ActionChipDemoState createState() => _ActionChipDemoState();
}

class _ActionChipDemoState extends State<ActionChipDemo> {
  List<String> _list = ["Apple", "Banana", "Lemon"];
  String _selectionStr = "Northing";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("ActionChip"),
      ),
      body: Container(
        child: Column(
          children: [
            Container(
              width: double.infinity,
              child: Text("当前选择: $_selectionStr"),
            ),
            Wrap(
              spacing: 8,
              runSpacing: 8,
              children: _list.map((tag) {
                return ActionChip(
                  label: Text(tag),
                  onPressed: () {
                    setState(() {
                      _selectionStr = tag;
                    });
                  },
                );
              }).toList(),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            _list = ["Apple", "Banana", "Lemon"];
            _selectionStr = "Northing";
          });
        },
        child: Icon(Icons.restore),
      ),
    );
  }
}
